package org.dev.pf.iof.systemmanage.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.dev.pf.iof.base.action.AbstractCommonAction;
import org.dev.pf.iof.systemmanage.model.IofMenuinfo;
import org.dev.pf.iof.systemmanage.service.IMenuManageService;
import org.dev.pf.iof.systemmanage.util.TreeUtil;

import com.jgeppert.struts2.jquery.tree.result.TreeNode;

public class MenuManageAction extends AbstractCommonAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 994014656334243672L;

	private String idaction;

	private String actionname;

	private List<TreeNode> menus = new ArrayList<TreeNode>();

	public String getIdaction() {
		return idaction;
	}

	public void setIdaction(String idaction) {
		this.idaction = idaction;
	}

	public String getActionname() {
		return actionname;
	}

	public void setActionname(String actionname) {
		this.actionname = actionname;
	}

	public List<TreeNode> getMenus() {
		return menus;
	}

	public void setMenus(List<TreeNode> menus) {
		this.menus = menus;
	}

	public String forSearchMainMenu() throws Exception {

		IMenuManageService theIMenuManageService = (IMenuManageService) getBean(IMenuManageService.class);

		List<IofMenuinfo> menuList = theIMenuManageService.searchMenu(null);

		menus.addAll(TreeUtil.buildingMenuList(menuList));

		return SUCCESS;

	}

	public String forShowMeunAction() throws Exception {
		actionname = StringUtils.substringAfterLast(idaction, "@");
		if (StringUtils.isBlank(actionname)) {
			return SUCCESS;
		}

		return INPUT;
	}

}
